/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ModelLayer;

import DBLayer.MapName;
import java.util.ArrayList;

/**
 *
 * @author Evil
 */
public class Order
{

    @MapName(ColumnName = "ID")
    private int orderID;
    private int employeeID;
    private int supplierID;
    private Employee employee;
    private Supplier supplier;
    private ArrayList<OrderLine> orderLines;
    private String deliveryStatus;
    private String deliveryDate;

    public Order(Employee employee, Supplier supplier)
    {
        this.employee = employee;
        this.supplier = supplier;
        orderLines = new ArrayList<OrderLine>();
    }

    public Order()
    {
        this(null, null);
    }

    public void addProduct(Product product, int quantity)
    {
        for (int i = 1; i <= quantity; i++)
        {
            orderLines.add(new OrderLine(product, 1));
        }
    }

    public void removeProduct(int index)
    {
        for (int i = 0; i < orderLines.size(); i++)
        {
            if (index == i)
            {
                OrderLine orderline = orderLines.get(i);

                int quantity = orderline.getQuantity();
                if (quantity > 1)
                {
                    orderline.setQuantity(quantity - 1);
                    return;
                }
                else
                {
                    orderLines.remove(orderline);
                }


            }
        }

    }

    /**
     * Get the value of orderID
     *
     * @return the value of orderID
     */
    public int getOrderID()
    {
        return orderID;
    }

    /**
     * Set the value of orderID
     *
     * @param orderID new value of orderID
     */
    public void setOrderID(int orderID)
    {
        this.orderID = orderID;
    }

    /**
     * Get the value of deliveryDate
     *
     * @return the value of deliveryDate
     */
    public String getDeliveryDate()
    {
        if (deliveryDate == null)
        {
            return "";
        }

        return deliveryDate;
    }

    /**
     * Set the value of deliveryDate
     *
     * @param deliveryDate new value of deliveryDate
     */
    public void setDeliveryDate(String deliveryDate)
    {
        this.deliveryDate = deliveryDate;
    }

    /**
     * Get the value of deliveryStatus
     *
     * @return the value of deliveryStatus
     */
    public String getDeliveryStatus()
    {
        if (deliveryStatus == null)
        {
            return "";
        }
        return deliveryStatus;
    }

    /**
     * Set the value of deliveryStatus
     *
     * @param deliveryStatus new value of deliveryStatus
     */
    public void setDeliveryStatus(String deliveryStatus)
    {
        this.deliveryStatus = deliveryStatus;
    }

    /**
     * Get the value of orderLines
     *
     * @return the value of orderLines
     */
    public ArrayList<OrderLine> getOrderLines()
    {
        return orderLines;
    }

    /**
     * Set the value of orderLines
     *
     * @param orderLines new value of orderLines
     */
    public void setOrderLines(ArrayList<OrderLine> orderLines)
    {
        this.orderLines = orderLines;
    }

    public int getSupplierID()
    {
        return supplierID;
    }

    public void setSupplierID(int supplierID)
    {
        this.supplierID = supplierID;
    }

    /**
     * Get the value of employeeID
     *
     * @return the value of employeeID
     */
    public int getEmployeeID()
    {
        return employeeID;
    }

    /**
     * Set the value of employeeID
     *
     * @param employeeID new value of employeeID
     */
    public void setEmployeeID(int employeeID)
    {
        this.employeeID = employeeID;
    }

    /**
     * Get the value of employee
     *
     * @return the value of employee
     */
    public Employee getEmployee()
    {
        return employee;
    }

    /**
     * Set the value of employee
     *
     * @param employee new value of employee
     */
    public void setEmployee(Employee employee)
    {
        this.employee = employee;
        this.employeeID = employee.getEmployeeID();
    }

    /**
     * Get the value of supplier
     *
     * @return the value of supplier
     */
    public Supplier getSupplier()
    {
        return supplier;
    }

    /**
     * Set the value of supplier
     *
     * @param supplier new value of supplier
     */
    public void setSupplier(Supplier supplier)
    {
        this.supplier = supplier;
        this.supplierID = supplier.getSupplierID();
    }
}
